home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Floppyshop 2
/
Floppyshop - 2.zip
/
Floppyshop - 2.iso
/
diskmags
/
0022-3.564
/
dmg-3442
/
st_applc
/
pf_sta12
/
listing1.asc
next >
Wrap
Text File
|
1992-04-03
|
8KB
|
190 lines
**
** Listing 1.
** Programmers' Forum, November 1991
**
** Fragment of code showing a method of
** forcing a reboot on a colour resolution
** change. This should be installed in an
** accessory.
**
** Assembler: asm v5.06
** Written: 11th September 1991
**
**
** Define the symbols we use...
**
MAX_SIZE equ $1060 Assumed maximum DESKTOP.INF size.
reset_vec equ $0004 System variables.
trap1 equ $0084
_bootdev equ $0446
GEMDOS equ 1 Operating system services.
Fopen equ $3D
Fclose equ $3E
Fread equ $3F
Fwrite equ $40
Fseek equ $42
Malloc equ $48
Mfree equ $49
XBIOS equ 14
Getrez equ 4
;=======================================================================
**
** Installation code for the resolution-change
** code. In most cases you would probably want
** to amalgamate this into your accessory's
** installation code. Note that, as written,
** this routine MUST be called in supervisor mode.
** _pbase is the Lattice C 5 variable that holds the
** address of the program's basepage. If you are using
** another system, you should ensure that the internal
** variable 'block' is set up as a pointer to the basepage.
**
install move.l __pbase,block Copy our basepage address.
move.l trap1,wrecker-4 Grab the GEMDOS trap.
move.l #wrecker,trap1 Install us.
rts
;=======================================================================
**
** This is the protection against nasty resolution changes.
** The initialisation code should splice this into the
** GEMDOS trap. Before splicing in, the internal variable
** 'block' should be set to the start of the program's memory
** block. Note the XBRA prefix for the handler.
**
dc.l 'XBRA'
dc.l 'RZCH' Our XBRA ID: ReZ CHange.
dc.l 0 Old GEMDOS trap vector.
wrecker tst.w recursive Recursive trap call ?
beq.s do_check No, we need to check malloc.
go_old move.l wrecker-4,a0 Don't parse recursive calls,
jmp (a0) Hand off immediately to system.
do_check btst #13,(sp) Were we in supervisor mode ?
beq.s 1$ No, args are on user stack.
lea 6(sp),a0 Point a0 to args on supervisor stack.
bra.s 2$ Skip on, all set up.
1$ move.l USP,a0 Fetch the user stack pointer.
2$ cmp.w #Mfree,(a0) GEMDOS Mfree call ?
bne.s go_old No, pass on to system now.
move.l 2(a0),a0 Fetch the address to be freed.
cmp.l block(pc),a0 Freeing our basepage ?
bne.s go_old No, give it back to the system.
;
; We have detected the unloading of this accessory.
; Now we have to fix the DESKTOP.INF file and reboot.
; Start by opening the file, allocating a buffer and
; reading the file into it.
;
st recursive Pass on all of our GEMDOS calls.
move.w _bootdev,d0 Make up the boot drive letter.
add.w #'A',d0
move.b d0,deskfile Fix up the DESKTOP.INF filename.
code pea MAX_SIZE Maximum length for DESKTOP.INF.
move.w #Malloc,-(sp) Get us a memory block for the file.
trap #GEMDOS
addq.l #6,sp
tst.l d0 Memory allocated OK ?
beq reboot No, bomb out.
move.l d0,a5 Save the buffer address.
move.w #1,-(sp) We will need R/W access to the file.
pea deskfile(pc)
move.w #Fopen,-(sp)
trap #GEMDOS Open the file.
addq.l #8,sp
tst.l d0 Any error ?
bmi reboot Yes, ice the system.
move.w d0,d7 Save the file handle.
move.l a5,-(sp) Space to read the file into.
pea MAX_SIZE Read at most about 4K of file.
move.w d0,-(sp) File handle.
move.w #Fread,-(sp) Read the file in now.
trap #GEMDOS
lea 12(sp),sp
tst.l d0 Did any error occur ?
bmi.s reboot Bomb it if so.
move.l d0,d6 Save the number of bytes read.
;
; Now reposition the file pointer so our amended
; block is written back to the correct part of the file.
;
clr.w -(sp) Seek from start of file.
move.w d7,-(sp) File handle.
clr.l -(sp) Right to the very start of the file.
move.w #Fseek,-(sp)
trap #GEMDOS Do it.
lea 10(sp),sp
tst.l d0 Bomb out on any error.
bmi.s reboot
;
; At this stage we simply scan the buffer for the entry
; that determines the resolution. This is a line of the
; format #E XX X?
; where ? is '1' for low res, '2' for medium and '3' for
; high resolution.
;
move.l a5,a0 Address start of file.
move.w d6,d1 Number of bytes in buffer.
subq.w #1,d1 Compensate for dbra.
moveq #'#',d0 Element prefix character.
1$ cmp.b (a0)+,d0 Scan for it.
beq.s 3$ Got one, so process it.
2$ dbra d1,1$ Loop until buffer exhausted.
bra.s reboot Resolution not found: error.
3$ cmp.b #'E',(a0) Miscellaneous config information ?
bne.s 2$ No, must be another command so skip.
;
; We have found the resolution configuration byte.
; All we do is to find the current resolution, and
; set the byte to the code for the other colour
; resolution.
;
move.l a0,a6 Copy the buffer pointer.
move.b #'1',6(a6) Assume new resolution is low.
move.w #Getrez,-(sp) Find out the current resolution.
trap #XBIOS
addq.l #2,sp
cmp.w #1,d0 Currently in medium resolution ?
beq.s 4$ Yes, our guess was right.
move.b #'2',6(a6) Wrong, our new resolution is medium.
;
; Now we just have to write out the updated file.
;
4$ move.l a5,-(sp) Write out from the buffer.
move.l d6,-(sp) Holds the real length of the file.
move.w d7,-(sp) File handle.
move.w #Fwrite,-(sp)
trap #GEMDOS Write the modified file out now.
lea 12(sp),sp
move.w d7,-(sp) Finish up the file handling,
move.w #Fclose,-(sp) ensuring that the file is written to
trap #GEMDOS the disk.
addq.l #4,sp
;
; Now it is safe to reset the system. This is
; also done immediately if there has been any
; error while the routine has been running.
;
reboot move.l reset_vec.w,a0 Jump to do a warm reset.
jmp (a0)
**
** Routine data area.
**
deskfile dc.b 'A:\DESKTOP.INF',0
block dc.l 0
recursive dc.w 0
END